﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Web.SessionState;

namespace HGZP.PLL
{
    /// <summary>
    /// 全局变量 的摘要说明。
    /// </summary>
    public class Export : System.Web.UI.Page
    {

        /// <summary>
        ///  将datagrid 的内容导出到excel (用于vs2003)
        /// </summary>
        /// <param name="ctl"></param>
        static public void ExportToExcel(System.Web.UI.Control mygridview)
        {

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            HttpContext.Current.Response.AddHeader("content-disposition",
            "attachment;filename=FileName.xls");
            //Response.Charset = utf
            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.ContentType = "application/vnd.xls";
            HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);




            mygridview.RenderControl(htmlWrite);

            HttpContext.Current.Response.Write(stringWrite.ToString());

            HttpContext.Current.Response.End();

        }
        //
       



    }

}